package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.CarLeaveLog;
import com.ruoyi.system.service.ICarLeaveLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车辆出场记录Controller
 * 
 * @author sunkai
 * @date 2022-11-01
 */
@RestController
@RequestMapping("/system/leavelog")
public class CarLeaveLogController extends BaseController
{
    @Autowired
    private ICarLeaveLogService carLeaveLogService;

    /**
     * 查询车辆出场记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarLeaveLog carLeaveLog)
    {
        startPage();
        List<Map<String,Object>> list = carLeaveLogService.selectCarLeaveLogListMap(carLeaveLog);
        return getDataTable(list);
    }

    /**
     * 导出车辆出场记录列表
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:export')")
    @Log(title = "车辆出场记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarLeaveLog carLeaveLog)
    {
        List<CarLeaveLog> list = carLeaveLogService.selectCarLeaveLogList(carLeaveLog);
        ExcelUtil<CarLeaveLog> util = new ExcelUtil<CarLeaveLog>(CarLeaveLog.class);
        util.exportExcel(response, list, "车辆出场记录数据");
    }

    /**
     * 获取车辆出场记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return AjaxResult.success(carLeaveLogService.selectCarLeaveLogById(id));
    }

    /**
     * 新增车辆出场记录
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:add')")
    @Log(title = "车辆出场记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarLeaveLog carLeaveLog)
    {
        return toAjax(carLeaveLogService.insertCarLeaveLog(carLeaveLog));
    }

    /**
     * 修改车辆出场记录
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:edit')")
    @Log(title = "车辆出场记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarLeaveLog carLeaveLog)
    {
        return toAjax(carLeaveLogService.updateCarLeaveLog(carLeaveLog));
    }

    /**
     * 删除车辆出场记录
     */
    @PreAuthorize("@ss.hasPermi('system:leavelog:remove')")
    @Log(title = "车辆出场记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(carLeaveLogService.deleteCarLeaveLogByIds(ids));
    }
}
